/**
 * Copyright (C) 2010  Johan Basson
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

package symorg.io;

import java.util.Vector;

/**
 * Tokenize a string using delimeter.
 * 
 * @author johan
 */
public class StringTokenizer {

    public static Vector tokenize(String data, char delim) {
        Vector items = new Vector();
        int pos = 0;
        StringBuffer sb = new StringBuffer();

        int len = data.length();
        for (int t=0;t < len;t++) {
            if (data.charAt(t) == delim) {
                if (sb.toString().trim().length() > 0 ){
                    items.addElement(sb.toString());
                }
                sb.setLength(0);
            } else {
                sb.append(data.charAt(t));
            }
        }

        if (sb.length() > 0) {
            items.addElement(sb.toString());
        }

        return items;
    }
}
